package com.budwk.app.sqfw.enums.datamange;

import com.budwk.app.common.config.AppException;
import com.budwk.app.sqfw.constants.CommonForAdminConstants;
import com.budwk.app.sqfw.utils.CommunityDataCleanUtils;
import com.budwk.app.util.adminUtils.CommonCheckUtils;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Optional;

@Getter
public enum TypeToPKeyEnum {
    DOOR_THREE_CARE("门前三包", "all", "placeName", CommunityDataCleanUtils.PROVINCE_MAIN_TABLE, CommunityDataCleanUtils.CITY_MAIN_TABLE, CommunityDataCleanUtils.DISTRICT_MAIN_TABLE, CommunityDataCleanUtils.COUNTY_MAIN_TABLE),
    GUANSHANHU_SECURITY_CHK("安全排查整治", "all", "theme", CommunityDataCleanUtils.PROVINCE_MAIN_TABLE, CommunityDataCleanUtils.CITY_MAIN_TABLE, CommunityDataCleanUtils.DISTRICT_MAIN_TABLE, CommunityDataCleanUtils.COUNTY_MAIN_TABLE),
    GUANSHANHU_SECURITY_CHK_FIRE_VIEW("安全排查整治", "消防", "isHydrantOperational,hasSafetyProtectionFacility,enterpriseSecurityTraining,makeEmergencyPlans,fireClearance,establishHazardMonitoring", CommunityDataCleanUtils.PROVINCE_MAIN_TABLE, CommunityDataCleanUtils.CITY_MAIN_TABLE, CommunityDataCleanUtils.DISTRICT_MAIN_TABLE, CommunityDataCleanUtils.COUNTY_MAIN_TABLE),
    GUANSHANHU_SECURITY_CHK_GAS_VIEW("安全排查整治", "燃气", "combustibleGasAlarm", CommunityDataCleanUtils.PROVINCE_MAIN_TABLE, CommunityDataCleanUtils.CITY_MAIN_TABLE, CommunityDataCleanUtils.DISTRICT_MAIN_TABLE, CommunityDataCleanUtils.COUNTY_MAIN_TABLE),
    GUANSHANHU_SECURITY_CHK_FOOD_VIEW("安全排查整治", "食品", "placeInOutNeat,thePrincipalIsResponsible", CommunityDataCleanUtils.PROVINCE_MAIN_TABLE, CommunityDataCleanUtils.CITY_MAIN_TABLE, CommunityDataCleanUtils.DISTRICT_MAIN_TABLE, CommunityDataCleanUtils.COUNTY_MAIN_TABLE),
    GUANSHANHU_SECURITY_CHK_LABOUR_VIEW("安全排查整治", "劳资", "payrollProblem", CommunityDataCleanUtils.PROVINCE_MAIN_TABLE, CommunityDataCleanUtils.CITY_MAIN_TABLE, CommunityDataCleanUtils.DISTRICT_MAIN_TABLE, CommunityDataCleanUtils.COUNTY_MAIN_TABLE),
    CAREPEOPLE_VISIT("关爱人员探访", "all", "name", CommunityDataCleanUtils.PROVINCE_MAIN_TABLE, CommunityDataCleanUtils.CITY_MAIN_TABLE, CommunityDataCleanUtils.DISTRICT_MAIN_TABLE, CommunityDataCleanUtils.COUNTY_MAIN_TABLE),
    SOCIETY_SECURITY("社会治安", "all", "address", CommunityDataCleanUtils.PROVINCE_MAIN_TABLE, CommunityDataCleanUtils.CITY_MAIN_TABLE, CommunityDataCleanUtils.DISTRICT_MAIN_TABLE, CommunityDataCleanUtils.COUNTY_MAIN_TABLE),
    SAFETY_PUBLICITY("平安建设宣传", "all", "address", CommunityDataCleanUtils.PROVINCE_MAIN_TABLE, CommunityDataCleanUtils.CITY_MAIN_TABLE, CommunityDataCleanUtils.DISTRICT_MAIN_TABLE, CommunityDataCleanUtils.COUNTY_MAIN_TABLE),
    LINHE_PROP_CURE("林河汛灾防治", "all", "address", CommunityDataCleanUtils.PROVINCE_MAIN_TABLE, CommunityDataCleanUtils.CITY_MAIN_TABLE, CommunityDataCleanUtils.DISTRICT_MAIN_TABLE, CommunityDataCleanUtils.COUNTY_MAIN_TABLE),
    PROVIDE_OLD_SERVICE("养老服务站巡查", "all", "address", CommunityDataCleanUtils.PROVINCE_MAIN_TABLE, CommunityDataCleanUtils.CITY_MAIN_TABLE, CommunityDataCleanUtils.DISTRICT_MAIN_TABLE, CommunityDataCleanUtils.COUNTY_MAIN_TABLE),
    CHILD_VISIT_RECORD("儿童探访记录", "all", "address", CommunityDataCleanUtils.PROVINCE_MAIN_TABLE, CommunityDataCleanUtils.CITY_MAIN_TABLE, CommunityDataCleanUtils.DISTRICT_MAIN_TABLE, CommunityDataCleanUtils.COUNTY_MAIN_TABLE),
    SPECIAL_OLDMAN_RECORD("特殊老年人探访", "all", "address", CommunityDataCleanUtils.PROVINCE_MAIN_TABLE, CommunityDataCleanUtils.CITY_MAIN_TABLE, CommunityDataCleanUtils.DISTRICT_MAIN_TABLE, CommunityDataCleanUtils.COUNTY_MAIN_TABLE);

    private final String type;// 类型
    private final String subType;// 子类型
    private final String key;// 主维度
    private final String viewProvince;// 查询省视图
    private final String viewCity;// 查询市视图
    private final String viewDistrict;// 查询区/县视图
    private final String viewCounty;// 查询街道视图

    TypeToPKeyEnum(String type, String subType, String key, String viewProvince, String viewCity, String viewDistrict, String viewCounty) {
        this.type = type;
        this.subType = subType;
        this.key = key;
        this.viewProvince = viewProvince;
        this.viewCity = viewCity;
        this.viewDistrict = viewDistrict;
        this.viewCounty = viewCounty;
    }

    /**
     * @param type
     * @return
     */
    public static TypeToPKeyEnum getByType(String type, String subType) {
        Optional<TypeToPKeyEnum> optional = Arrays.stream(values()).filter(e -> {
            return e.getType().contains(type) && subType.equals(e.getSubType());
        }).findFirst();
        return optional.orElse(null);
    }

    /**
     * 根据类型和参数获取表名
     *
     * @param
     * @return
     */
    public static String getViewTable(String type, String subType) {
        Optional<TypeToPKeyEnum> optional = Arrays.stream(values()).filter(e -> {
            return e.getType().contains(type) && subType.equals(e.getSubType());
        }).findFirst();
        TypeToPKeyEnum typeToPKeyEnum = optional.get();
        String areaLevel = CommonCheckUtils.checkUserArea();
        if (StringUtils.isEmpty(areaLevel)) {
            throw new AppException("用户行政区域参数错误!");
        }
        String resultArea = "";
        switch (areaLevel) {
            case CommonForAdminConstants.PROVINCE:
                resultArea = typeToPKeyEnum.getViewProvince();
                break;
            case CommonForAdminConstants.CITY:
                resultArea = typeToPKeyEnum.getViewCity();
                break;
            case CommonForAdminConstants.DISTRICT:
                resultArea = typeToPKeyEnum.getViewDistrict();
                break;
            case CommonForAdminConstants.COUNTY:
                resultArea = typeToPKeyEnum.getViewCounty();
                break;
        }
        return resultArea;
    }
}
